﻿namespace EyeOpen.ExceptionLogging.Windows
{
	using System;
	using System.Windows.Forms;

	using EyeOpen.Logging;

	public partial class MainForm : Form
	{
		private readonly ListBoxLogger listBoxLogger;

		public MainForm()
		{
			InitializeComponent();

			listBoxLogger =
				new ListBoxLogger(this.exceptionListBox);

			DependencyResolver
				.Register<ILogger>(this.listBoxLogger);
		}

		protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
		{
			DependencyResolver
				.Remove<ILogger>(this.listBoxLogger);
		}

		private void ThrowButtonClick(object sender, EventArgs e)
		{
			new DisposableObject()
				.UsingWithLog(
					o =>
						{
							o.Method();
							throw new Exception("Test exception.");
						});
		}
	}
}